package com.cl.edu.web.teacher;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.cl.core.orm.Page;
import com.cl.edu.entity.Message;
import com.cl.edu.service.teacher.MessageManager;
import com.cl.edu.service.teacher.TeacherManager;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 站内消息的相关操作
 * @author Administrator
 *
 */

@Results({ @Result(name = "success", location = "tc_news.jsp") })
public class MessageAction extends ActionSupport{
	@Autowired
	private TeacherManager teacherManager;
	@Autowired
	private MessageManager messageManager;
	
	private Long id;					//登录用户id
	private Integer  msgId;				//消息id
	
	private Page<Message> page = new Page<Message>();//站内消息列表
	
	/**
	 * 进入站内消息时显示列表
	 */
	public String execute() throws Exception {
		if (!page.isOrderBySetted()) {
			page.setOrderBy("createTime");
			page.setOrder(Page.DESC);
		}
		page = messageManager.getMessages(page,id);
		return "success";
	}
	
	/**
	 * 更新消息状态
	 * @return
	 * @throws Exception
	 */
	public String set() throws Exception{
		Message message = messageManager.getMessage(msgId);
		message.setIsRead(1);
		messageManager.updateMessage(message);
		addActionMessage("更改状态成功!");
		return execute();
	}
	
	/**
	 * 删除一条消息 
	 * @return
	 * @throws Exception
	 */
	public String del() throws Exception {
		messageManager.delMessage(msgId);
		addActionMessage("删除成功!");
		return execute();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Page<Message> getPage() {
		return page;
	}

	public void setPage(Page<Message> page) {
		this.page = page;
	}

	public Integer getMsgId() {
		return msgId;
	}

	public void setMsgId(Integer msgId) {
		this.msgId = msgId;
	}

	
	
}
